Fix for allowing a weight file to be written when it does not exist when using filename argument.#234
Fix for allowing a weight file to be written when it does not exist when using filename argument.#234jr3cermak wants to merge 2 commits intopangeo-data:masterfrom
Conversation
|
If this PR is approved, the CI test would have to be changed. The logic would permit that weight file to be created in this case where reuse_weights=True, filename='fakewgts.nc'. It would be an error if 'fakewgts.nc' was not created. If the arguments were reuse_weights=True, weights='fakewgts.nc', that should generate an OSError. |
|
@jr3cermak IMHO setting |
|
ok. Is see how the instead of needing to do something like: |
This might address issues #153 and #202. I had been using xESMF version 0.3.0 and now improving code to use the latest 0.7.0. In version 0.3.0, with Regridding(reuse_weights=True and filename="...") and the filename does not exist, the weights file is created on the first pass and reused in subsequent uses. In version 0.7.0, we encounter this error when the weights file does not exist. We do not pre-generate a weights file,
This patch restores the previous behavior from 0.3.0.
The logic is just a little complex.
If reuse_weights is False, compute new weights each time unless the weights argument is specified.
The weights argument, if a filename, MUST exist.
If reuse_weights is True, use the weights argument if provided. Override weights argument, if filename is provided. If the weights argument is a filename, it MUST exist. If a filename argument is provided, override the weights argument. If the provided filename exists, use it for the weights otherwise compute new weights and trigger saving the weights to the filename in the first pass. Subsequent calls will utilize the new and existing filename.
Maybe add some wording to the function arguments to further clarify use.